/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.targeter.rulesengine.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.targeter.rulesengine.service.modelsLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author jsalaice
 */
public class modelsClp extends BaseModelImpl<models> implements models {
	public modelsClp() {
	}

	public Class<?> getModelClass() {
		return models.class;
	}

	public String getModelClassName() {
		return models.class.getName();
	}

	public long getPrimaryKey() {
		return __id;
	}

	public void setPrimaryKey(long primaryKey) {
		set_id(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(__id);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("_id", get_id());
		attributes.put("model", getModel());
		attributes.put("active", getActive());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long _id = (Long)attributes.get("_id");

		if (_id != null) {
			set_id(_id);
		}

		String model = (String)attributes.get("model");

		if (model != null) {
			setModel(model);
		}

		Boolean active = (Boolean)attributes.get("active");

		if (active != null) {
			setActive(active);
		}
	}

	public long get_id() {
		return __id;
	}

	public void set_id(long _id) {
		__id = _id;
	}

	public String getModel() {
		return _model;
	}

	public void setModel(String model) {
		_model = model;
	}

	public boolean getActive() {
		return _active;
	}

	public boolean isActive() {
		return _active;
	}

	public void setActive(boolean active) {
		_active = active;
	}

	public BaseModel<?> getmodelsRemoteModel() {
		return _modelsRemoteModel;
	}

	public void setmodelsRemoteModel(BaseModel<?> modelsRemoteModel) {
		_modelsRemoteModel = modelsRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			modelsLocalServiceUtil.addmodels(this);
		}
		else {
			modelsLocalServiceUtil.updatemodels(this);
		}
	}

	@Override
	public models toEscapedModel() {
		return (models)Proxy.newProxyInstance(models.class.getClassLoader(),
			new Class[] { models.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		modelsClp clone = new modelsClp();

		clone.set_id(get_id());
		clone.setModel(getModel());
		clone.setActive(getActive());

		return clone;
	}

	public int compareTo(models models) {
		int value = 0;

		if (get_id() < models.get_id()) {
			value = -1;
		}
		else if (get_id() > models.get_id()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		modelsClp models = null;

		try {
			models = (modelsClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = models.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{_id=");
		sb.append(get_id());
		sb.append(", model=");
		sb.append(getModel());
		sb.append(", active=");
		sb.append(getActive());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append("com.targeter.rulesengine.model.models");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>_id</column-name><column-value><![CDATA[");
		sb.append(get_id());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>model</column-name><column-value><![CDATA[");
		sb.append(getModel());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>active</column-name><column-value><![CDATA[");
		sb.append(getActive());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long __id;
	private String _model;
	private boolean _active;
	private BaseModel<?> _modelsRemoteModel;
}